<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>01</title>
</head>
<body>
<script>
    /*
     * 原型模式 2
     * 不能够像构造函数一样定义任意变量值的
     * 在包含引用类型的属性被改变是会影响其他对象的该属性也被改变
     *
     */
    function Animal() {}

    Animal.prototype ={
        //constructor: Animal,
        name : "Animal",
        friends : ["dog","cat"],
        sayName : function () {
            alert(this.name);
        }
    }

    var a1 = new Animal();
    var a2 = new Animal();
    alert(a1.sayName == a2.sayName); //true
    a1.sayName();

    alert(Animal.prototype.constructor == Animal); //true

    a1.friends.push("snake");
    alert(a2.friends); //["dog","cat","snake"]
</script>
</body>
</html>